function Promise(callback){
this.PromiseState = 'pending'
this.PromiseResult = undefined

const resolve = data => {
    if(this.PromiseState != 'pending') return
    this.PromiseState = 'fulfilled'
    this.PromiseResult = data
}
const reject = error => {
    if(this.PromiseState != 'pending') return
    this.PromiseState = 'rejected'
    this.PromiseResult = error
}

try {
    callback(resolve,reject)
} catch (error) {
    reject(error.toString())
}
}

Promise.prototype.then = function(resolve,reject) {
    let data = undefined
    if(this.PromiseState == 'fulfilled'){
        data = resolve(this.PromiseResult)
    }
    if(this.PromiseState == 'rejected'){
        data = reject(this.PromiseResult)
    }
    return new Promise((resolve,reject) => {
        if(data instanceof Promise){
        data.then = (
            res => resolve(res),
            err => reject(err)
        )
        }else{
            resolve(data)
        }
    })
}
Promise.prototype.catch = function() {}
Promise.prototype.finally = function() {}
Promise.resolve = function(data) {
    return new Promise((resolve,reject) => {
        resolve(data)
    })
}
Promise.reject = function(data) {
    return new Promise((resolve,reject) => {
        reject(data)
    })
}
Promise.all = function() {}
Promise.race = function() {}
Promise.allSettled = function() {}
Promise.any = function() {}